﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Ch9RSS_WP8.Resources;
using Ch9_Portable.Models;
using Ch9RSS_Universal.ViewModels;
using System.Diagnostics;

namespace Ch9RSS_WP8
{
    public partial class MainPage : PhoneApplicationPage
    {
        private HubPageViewModel defaultViewModel = App.HubVM;
        public HubPageViewModel DefaultViewModel
        {
            get { return this.defaultViewModel; }
        }
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            this.DataContext = this.DefaultViewModel;
            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

        private void FeaturedItem_Changed(object sender, SelectionChangedEventArgs e)
        {
            // One way to transfer a context from page to page is to pass a 
            //   parameter pointing to an item in an existing ViewModel
            if (e.AddedItems != null && e.AddedItems.Count == 1)
            {
                var selectedItem = (Ch9Item)e.AddedItems[0];
                App.ItemVM.SetCh9Item(selectedItem);
                NavigationService.Navigate(new Uri("/ItemPage.xaml", UriKind.Relative));
               
            }
        }

        private void SeriesItem_Changed(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems != null && e.AddedItems.Count == 1)
            {
                var selectedItem = (Ch9Item)e.AddedItems[0];

                // Another way to transfer context from page to page is to 
                //   pass information from one ViewModel to another one
                App.SectionVM.LoadSelectedSeries(selectedItem);
                NavigationService.Navigate(new Uri("/SectionPage.xaml", UriKind.Relative));

            }
        }

        private void ShowItem_Changed(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems != null && e.AddedItems.Count == 1)
            {
                var selectedItem = (Ch9Item)e.AddedItems[0];
                App.SectionVM.LoadSelectedSeries(selectedItem);
                NavigationService.Navigate(new Uri("/SectionPage.xaml", UriKind.Relative));
            }
        }

        private void TestGridLoaded(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Boo!");
        }

        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}
    }
}